﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SmartWarehouse.Common;
using SmartWarehouse.BussinessLogic.Basis;
using SmartWarehouse.ORM.Entity;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            InitMenu();
        }
    }

    private void InitMenu()
    {
        RightFacade rightFacade = new RightFacade();
        SwRight[] rights = rightFacade.GetUserPages(this.UserName);
        var orderMenu = rights.OrderBy(menu => menu.Sequence);

        foreach (SwRight right in orderMenu)
        {
            MenuItem item = new MenuItem();
            item.Text = right.Page_name;
            item.NavigateUrl = right.Pageurl;
            menu.Items.Add(item);
        }
    }




    #region Get the login user 
    private string UserName
    {
        get
        {
            return this.Session["UserName"] as string;
        }
    }
    #endregion
    protected void lbLogout_Click(object sender, EventArgs e)
    {
        ClearCookieOfUser();
        this.Response.Redirect("~/Login.aspx");
    }

    private void ClearCookieOfUser()
    {
        Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
    }
}
